Imports PTT.CarRes.Data

Public Class ClassQueryInvReserveDataTime
    Public Function Add(ByVal InvReserveDataTime As QueryInvReserveDataTime, ByVal StrConn As String) As Boolean
        Dim ClsInvReserveDataTime As New ClassInvReserveDataTime
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvReserveDataTime.ConnectionOpen(StrConn)
        Dim ret As Boolean = False
        With ClsInvReserveDataTime
            .DayId = InvReserveDataTime.DayId
            .ReserveDay = InvReserveDataTime.ReserveDay
            .StartTime = InvReserveDataTime.StartTime
            .StopTime = InvReserveDataTime.StopTime
            .ReserveId = InvReserveDataTime.ReserveId
            ret = .USP_Save(Conn)
        End With
        ClsInvReserveDataTime.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Edit(ByVal InvReserveDataTime As QueryInvReserveDataTime, ByVal StrConn As String) As Boolean
        Dim ClsInvReserveDataTime As New ClassInvReserveDataTime
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvReserveDataTime.ConnectionOpen(StrConn)
        Dim ret As Boolean = False
        With ClsInvReserveDataTime
            .DayId = InvReserveDataTime.DayId
            .Load(Conn)
            .ReserveDay = InvReserveDataTime.ReserveDay
            .StartTime = InvReserveDataTime.StartTime
            .StopTime = InvReserveDataTime.StopTime
            .ReserveId = InvReserveDataTime.ReserveId
            ret = .USP_Update(Conn)
        End With
        ClsInvReserveDataTime.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Delete(ByVal InvReserveDataTime As QueryInvReserveDataTime, ByVal StrConn As String) As Boolean
        Dim ClsInvReserveDataTime As New ClassInvReserveDataTime
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvReserveDataTime.ConnectionOpen(StrConn)
        Dim ret As Boolean = False
        With ClsInvReserveDataTime
            .DayId = InvReserveDataTime.DayId
            .Load(Conn)
            ret = .USP_Delete(Conn)
        End With
        ClsInvReserveDataTime.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Search(Optional ByVal ParaDayId As String = "", _
    Optional ByVal ParaReserveDay As String = "", _
    Optional ByVal ParaReserveId As String = "", Optional ByVal StrConn As String = "") As QueryInvReserveDataTimes
        Dim ClsInvReserveDataTime As New ClassInvReserveDataTime
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvReserveDataTime.ConnectionOpen(StrConn)
        Dim ret As QueryInvReserveDataTimes = Nothing
        Dim str As String = ""
        Dim Condition As String = ""
        str &= " Select * from InvReserveDataTime"
        If ParaDayId & "" <> "" Then
            If Condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(DayId = " & ParaDayId & ")"
        End If
        If ParaReserveDay & "" <> "" Then
            If Condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(ReserveDay like '%" & ParaReserveDay & "%')"
        End If
        If ParaReserveId & "" <> "" Then
            If Condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(ReserveId = " & ParaReserveId & ")"
        End If

        If Condition & "" <> "" Then
            str &= " where "
            str &= Condition
        End If
        Dim ds As DataSet
        With ClsInvReserveDataTime
            ds = .BindData(Conn, , , str)
            If Not ds Is Nothing Then
                Dim i As Integer
                Dim results As New QueryInvReserveDataTimes

                Try
                    For i = 0 To ds.Tables(0).Rows.Count - 1
                        With ds.Tables(0).Rows(i)

                            results.Add(New QueryInvReserveDataTime( _
                              .Item("DayId") & "", _
                              .Item("ReserveDay") & "", _
                              .Item("StartTime") & "", _
                              .Item("StopTime") & "", _
                              .Item("ReserveId") & "" _
                            ))
                        End With
                    Next
                    ret = results
                Catch ex As Exception
                    Return Nothing
                    'Throw New DALException(ex.Message)
                End Try
            End If
        End With
        ClsInvReserveDataTime.ConnectionClose(Conn)
        Return ret
    End Function
    Public Function Load(Optional ByVal ParaDayId As String = "", _
    Optional ByVal ParaReserveId As String = "", Optional ByVal StrConn As String = "") As QueryInvReserveDataTimes
        Dim ClsInvReserveDataTime As New ClassInvReserveDataTime
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvReserveDataTime.ConnectionOpen(StrConn)
        Dim ret As QueryInvReserveDataTimes = Nothing
        Dim str As String = ""
        Dim Condition As String = ""
        str &= " Select * from InvReserveDataTime"
        If ParaDayId & "" <> "" Then
            If Condition & "" <> "" Then Condition &= " and "
            Condition &= "(DayId = " & ParaDayId & ")"
        End If
        If ParaReserveId & "" <> "" Then
            If Condition & "" <> "" Then Condition &= " and "
            Condition &= "(ReserveId = " & ParaReserveId & ")"
        End If

        If Condition & "" <> "" Then
            str &= " where "
            str &= Condition
        Else
            Return Nothing
            Exit Function
        End If
        Dim ds As DataSet
        With ClsInvReserveDataTime
            ds = .BindData(Conn, , , str)
            If Not ds Is Nothing Then
                Dim i As Integer
                Dim results As New QueryInvReserveDataTimes

                Try
                    For i = 0 To ds.Tables(0).Rows.Count - 1
                        With ds.Tables(0).Rows(i)

                            results.Add(New QueryInvReserveDataTime( _
                              .Item("DayId") & "", _
                              .Item("ReserveDay") & "", _
                              .Item("StartTime") & "", _
                              .Item("StopTime") & "", _
                              .Item("ReserveId") & "" _
                            ))
                        End With
                    Next
                    ret = results
                Catch ex As Exception
                    Return Nothing
                    'Throw New DALException(ex.Message)
                End Try
            End If
        End With
        ClsInvReserveDataTime.ConnectionClose(Conn)
        Return ret
    End Function
End Class